package model.eval;

import enums.TestPanelEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import misc.BundlesProvider;
import model.mchoice.MCItem;
import model.mchoice.MCItemSet;

import java.util.List;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Ejercicio de multiple choice;
 *
 * @author Jose Martin Rozanec;
 */
public class TestExerciseMChoice extends TestExcercise {
    /**
     * Constructor;
     */
    public TestExerciseMChoice() {
        this.panelEnum = TestPanelEnum.MULTIPLE_CHOICE;
    }

    public int getAchievedScore() {
        int score = 0;
        List<MCItem> solutionSet = ((MCItemSet) getExcerciseData()).getMCItems();
        List<MCItem> studentsSet = ((MCItemSet) getStudentsSolution()).getMCItems();
        for (int j = 0; j < solutionSet.size(); j++) {
            score = score + (int) solutionSet.get(j).getResult(studentsSet.get(j).getSolutionStatus());
        }
        return score;
    }

    public String toString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.MULTIPLE_CHOICE.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]");
        List<MCItem> items = ((MCItemSet) getExcerciseData()).getMCItems();
        for (int j = 0; j < items.size(); j++) {
            buffer.append("\n" + items.get(j).toString());
        }
        return buffer.toString();
    }

    public String getStudentSolutionString() {
        StringBuffer buffer = new StringBuffer();
        buffer.append(
                BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE).getString(TextBundleEnum.MULTIPLE_CHOICE.toString()));
        buffer.append(" [" + getCorrectScore() + "] [" + getIncorrectScore() + "]");
        List<MCItem> items = ((MCItemSet) getStudentsSolution()).getMCItems();
        for (int j = 0; j < items.size(); j++) {
            buffer.append("\n" + items.get(j).toString());
        }
        return buffer.toString();
    }

    /**
     * Devuelve el puntaje obtenido por correcta resolucion del ejercicio;
     *
     * @return int;
     */
    public int getCorrectScore() {
        return ((MCItemSet) getExcerciseData()).getPuntuation();
    }

    /**
     * Devuelve el puntaje obtenido por la incorrecta resolucion del ejercicio;
     *
     * @return int;
     */
    public int getIncorrectScore() {
        List<MCItem> mcItems = ((MCItemSet) getExcerciseData()).getMCItems();
        int incorrectScore = 0;
        for (int j = 0; j < mcItems.size(); j++) {
            incorrectScore = incorrectScore + mcItems.get(j).getIncorrectPunctuation();
        }
        return incorrectScore;
    }
}
